#{extends 'adminm/frame.html' /}

#{set 'moreScripts'}
<script src="@{'/public/javascripts/jquery-ui-1.8.10.custom.min.js'}" type="text/javascript" charset="utf-8"></script>
<script src="@{'/public/pager/jquery.pager.js'}" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" src="@{'/public/uploadify/swfobject.js'}"></script>
<script type="text/javascript" src="@{'/public/uploadify/jquery.uploadify.v2.1.4.min.js'}"></script>
#{/set}
#{set 'moreStyles'}
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/pager/Pager.css'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/table.scss'}" />

<link href="@{'/public/uploadify/uploadify.css'}" type="text/css" rel="stylesheet" />
#{/set}
#{set 'activeItem'}3#{/set}

<div class="navigationBar">
	<table>
		<tr>
			<td><img src="@{'/public/images/navigationHouse.gif'}"></td>
			<td><strong>当前位置：</strong></td>
			<td>
				<a href="/admin">首页</a>
				>>
				<a href="#">商品管理</a>
				>>
				<a href="/admin/brand/index">品牌管理</a>
				>>
				<font class="current">新建品牌</font>
			</td>
		</tr>
	</table>
</div>
<script language="javascript">
$(function(){
	/* uploadify2 */
	$('#image_upload').uploadify({
	    uploader	: '@{'/public/uploadify/uploadify.swf'}',
	    script		: '@{Attachments.create_uploadify}',
	    cancelImg	: '@{'/public/uploadify/cancel.png'}',
	    fileDataName: 'file',
	    fileExt     : '*.jpg;*.gif;*.png',
		fileDesc    : 'Image Files (.JPG, .GIF, .PNG)',
		sizeLimit   : 409600,
    	auto		: true,
    	onComplete	: function(event, ID, fileObj, response, data){
    		//显示附件
    		var getAttachmentAction = #{jsAction @Attachments.show(':id') /}
    		$("#image").attr('src', getAttachmentAction({id: response}));
    		//将附件ID添加到form里面
    		$("#image_upload").val(response);
    	}
	});
});
function doSubmit() {
	$("#form1").submit();
}
function reset() {
	window.location.href="/admin/brand/new";
}

function cleanImage() {
	$("#image").attr('src', "@{'public/images/image-placeholder.png'}");
	//将附件ID添加到form里面
	$("#image_upload").val("");
}
</script>
<div id="errMsg" class="error">
	#{error 'errMsg'/}
</div>
<table class="table_edit">
	<thead>
		<tr>
			<th colspan="2">新建品牌</th>
		</tr>
	</thead>
	<tbody>
		#{form @admin.brands.create(), name:'form1', id:'form1'}
		<tr>
			<td class="left" width="40%">名字：</td>
			<td>
				<input type="text" name='brand.name' maxlength="30" value="${brand.name}">
				<font class="require">*</font>&nbsp;
				<span class="error">#{error 'brand.name' /}</span>
			</td>
		</tr>
		<tr>
			<td class="left">图片：</td>
			<td>
				请上传品牌图片，大小不能超过400Kb.<br>
				<img id="image" class="midImg_brand" src="@{'/public/images/image-placeholder.png'}"/>
				<input type="button" onClick="cleanImage()" value="清空" />
				<font class="require">*</font>&nbsp;
				<span class="error">#{error 'brand.image' /}</span>
    			<p>
	    			<input id="image_upload" type="text" name="brand.image.id" />
    			</p>
			</td>
		</tr>
		<tr>
			<td class="left">说明：</td>
			<td>
				<textarea name="brand.common" hight="60px" width="100%">${brand.common}</textarea>
				<span class="error">#{error 'brand.common' /}</span>
			</td>
		</tr>
		#{/form}
	</tbody>
</table>
<br>
<center>
	<input type="button" value="保存品牌" onClick="doSubmit()">&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="button" value="重置数据" onClick="reset()">
</center>